package com.example.twodb.controller;

import com.example.twodb.Dao.db1.UserMapper;
import com.example.twodb.Dao.db2.UserMapper2;
import com.example.twodb.pojo.User;
import com.example.twodb.util.HttpResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * TODO
 *
 * @date 2021/8/24 下午 14:38
 */
@RestController
public class testController {


    final
    UserMapper2 userMapper2;
    final
    UserMapper userMapper;

    public testController(UserMapper2 userMapper2, UserMapper userMapper) {
        this.userMapper2 = userMapper2;
        this.userMapper = userMapper;
    }


    @GetMapping("/selectAllUser")
    public HttpResult selectAllCenterName() {

        List<User> centers = userMapper2.getUser();

        return HttpResult.newSuccess().add("data", centers);
    }

    @GetMapping("/insterUser")
    public HttpResult insterUser(String name) {

        try {
            userMapper.insterUser(name);
        } catch (Exception e) {
            e.printStackTrace();
            return HttpResult.newError("失败！");
        }

        return HttpResult.newSuccess();
    }


}
